$(function() {
    var filterCmp,kuCityObj;
    var photo_details_panel;
    var photo_details_cmp;


    var formSuperclass = sjApp.extend(superclass,{
        afterRender : function(){
            //filterCmp
            var me = this;
            if(this.dataIndex){
                var dom = this.getDom();
                if(dom.is('input')){
                    dom.keyup(function(){
                        filterCmp.options.changeData(me);
                    });
                }else if(dom.is('select')){
                    dom.change(function(){
                        filterCmp.options.changeData(me);
                    });
                }
            }
        },
        getDom:function(){
            if(!this.inputEl){
                this.inputEl = $('#'+this.id);
            }
            return this.inputEl;
        },
        reset : function(multipleFlag){
            var dom =  this.getDom();
            var placeholder;
            if(this.getPlaceholder instanceof Function){
                placeholder = this.getPlaceholder(multipleFlag);
                dom.attr('placeholder',placeholder);
            }
            dom.val('');
        },
        setValue : function(data,multipleFlag){
            if(this.dataIndex){
                var v = data[this.dataIndex];
                if(multipleFlag){
                    var curV = this.getDom().val();
                    if(curV != v){
                        this.reset(multipleFlag);
                    }
                }else{
                    this.getDom().val(v||'');
                }
            }
        },
        getValue : function(){
            return this.getDom().val();
        }
    });

    var check_super;
    !function(){
        var itemTpl;
        check_super = sjApp.extend(formSuperclass,{
            reset : function(){
                this.btns.removeClass('active').addClass('secondary');
            },
            setValue : function(data,multipleFlag,btndom){
                var dom = this.getDom();
                if(this.dataIndex){
                    if(data){
                        var v = data[this.dataIndex];
                        var oldValue = '';
                        if(multipleFlag){
                            oldValue = dom.find('.active').val();
                            if(oldValue!=v){
                                this.reset();
                                return;
                            }
                        }
                    }
                    if((!btndom||!btndom.length) && data){
                        btndom = dom.find('[data-value="'+v+'"]');
                    }
                    if(btndom && btndom.length){
                        btndom.addClass('active').removeClass('secondary');
                    }
                }
            },
            getValue : function(){
                return this.getDom().find('.active').data('value');
            },
            createItems : function () {
                var me = this;
                var btns = this.btns = this.El.find('.button');
                if(btns.length > 2){
                    btns.width(100/btns.length+'%');
                }
                btns.click(function(){
                    me.reset();
                    me.setValue(null,false,$(this));
                    filterCmp.options.changeData(me);
                });
            },
            init : function () {
                this.El = $(itemTpl({
                    id : this.id,
                    title : this.title,
                    datas : this.datas
                }));
                return this.El;
            }
        });
        check_super.init = function () {
            Handlebars.registerHelper('getCls', function(obj,first,last,options) {
                if(!last && !first){
                    return ' b_center';
                }
            });
            itemTpl = Handlebars.compile($('#tmpl-imgType_item').html());
        };
    }();
    var cmp = function() {};
    cmp.prototype = {
        cmp_title : function () {
            var itemTpl;
            var cm = sjApp.extend(formSuperclass,{
                id : 'img_title',
                dataIndex : 'title',
                init : function () {
                    this.El = $(itemTpl({
                        id : this.id,
                        title : '标题'
                    }));
                    return this.El;
                },getPlaceholder:function(multipleFlag){
                    if(multipleFlag){
                        return '多个标题在所选图片中';
                    }else{
                        return '';
                    }
                }
            });
            cm.init = function () {
                itemTpl = Handlebars.compile($('#tmpl-title_item').html());
            };
            return cm;
        }(),
        cmp_category : function () {
            var itemTpl;
            var cm = sjApp.extend(formSuperclass,{
                id : 'category_type',
                dataIndex : 'categoryId',
                init : function () {
                    this.El = $(itemTpl({
                        id : this.id,
                        data : cur_category
                    }));
                    return this.El;
                },createItems : function () {
                }
            });
            cm.init = function () {
                itemTpl = Handlebars.compile($('#tmpl-category_item').html());
            };
            return cm;
        }(),
        cmp_imgType : function () {
            var cm = sjApp.extend(check_super,{
                id : 'cmp_imgType',
                title : '图片类型',
                dataIndex : 'type',
                datas :  [{
                    value : 10311,
                    name : '摄影'
                },{
                    value : 10153,
                    name : '绘画插画'
                }]
            });
            return cm;
        }(),
        cmp_imgColor : function () {
            var cm = sjApp.extend(check_super,{
                id : 'cmp_imgColor',
                title : '画面色彩',
                dataIndex : 'color',
                datas :  [{
                    value : '12009',
                    name : '黑白'
                },{
                    value : 12004,
                    name : '彩色'
                }]
            });
            return cm;
        }(),
        cmp_shotEnv : function () {
            var cm = sjApp.extend(check_super,{
                id : 'cmp_shotEnv',
                title : '拍摄环境',
                dataIndex : 'shotEnv',
                datas :  [{
                    value : 4236,
                    name : '户外'
                },{
                    value : 36408,
                    name : '室内'
                },{
                    value : 4247,
                    name : '影棚拍摄'
                },{
                    value : 4244,
                    name : '都市风光'
                },{
                    value : 9873,
                    name : '自然风光'
                }]
            });
            return cm;
        }(),
        cmp_picDateTime : function () {
            var itemTpl;
            var cm = sjApp.extend(formSuperclass,{
                id : 'img_picDateTime',
                dataIndex : 'shotTime',
                init : function () {
                    this.El = $(itemTpl({
                        id : this.id,
                        title : '拍摄时间'
                    }));
                    return this.El;
                },
                afterRender : function(){
                    var me = this;
                    var dom = this.getDom();
                    dom.datetimepicker({
                        scrollInput : false,
                        lang: 'ch',      //语言选择中文
                        format: 'Y-m-d H:i:s',      //格式化日期
                        //timepicker: false,    //关闭时间选项
                        yearStart: 2000,     //设置最小年份
                        yearEnd: 2050, //设置最大年份,
                        todayButton: false, //关闭选择今天按钮
                        onChangeDateTime: function () {
                            filterCmp.options.changeData(me);
                        }
                    });
                }
            });
            cm.init = function () {
                itemTpl = Handlebars.compile($('#tmpl-title_item').html());
            };
            return cm;
        }(),
        cmp_picLocation : function () {
            var itemTpl;
            var cm = sjApp.extend(formSuperclass,{
                id : 'img_picLocation',
                dataIndex : 'city',
                init : function () {
                    this.El = $(itemTpl({
                        id : this.id,
                        title : '拍摄地点'
                    }));
                    return this.El;
                },
                afterRender : function(){
                    var me = this;
                    var dom = this.getDom();
                    dom.kuCity({
                        onSelectCity:function(){
                            filterCmp.options.changeData(me);
                        }
                    });
                    dom.keyup(function(){
                        filterCmp.options.changeData(me);
                    });
                }
            });
            cm.init = function () {
                itemTpl = Handlebars.compile($('#tmpl-title_item').html());
            };
            return cm;
        }(),
        cmp_imgPepole : function () {
            var itemTpl;
            var c = sjApp.extend(check_super,{
                id : 'cmp_imgPepole',
                title : '画面人数',
                dataIndex : 'number',
                datas :  [{
                    value : 4233,
                    name : '1'
                },{
                    value : 4215,
                    name : '2'
                },{
                    value : 4221,
                    name : '3-5'
                },{
                    value : 4219,
                    name : '6-10'
                },{
                    value : 4224,
                    name : '11+'
                },{
                    value : 12109,
                    name : '无人'
                }]
            });
            return c;
        }(),
        cmp_rights : function () {
            var itemTpl;
            var cm = sjApp.extend(formSuperclass,{
                id : 'cmp_rights',
                dataIndex : 'rightCategory',
                setValue : function(data){
                    cm.superclass.setValue.apply(this,arguments);
                    this.showOrHide(data.rightCategory);
                },
                showOrHide : function(v){
                    if (!v || v == 'NR') {
                        this.hideList();
                    }else{
                        this.showList();
                    }
                },
                showList : function(){
                    this.parentEl.addClass('showlist');
                    var listEl = $('#cmp_rights_list');
                    if (listEl.length) {
                        listEl.removeClass('hidden');
                    }
                },
                hideList : function(){
                    this.parentEl.removeClass('showlist');
                    var listEl = $('#cmp_rights_list');
                    if (listEl.length) {
                        listEl.addClass('hidden');
                    }
                },
                init : function () {
                    this.El = $('<div></div>');
                    this.El.append(itemTpl({
                        id : this.id
                    }));
                    return this.El;
                },initEvent : function () {
                    var me = this;
                    this.El.find('#'+this.id).change(function(){
                        var _this = $(this);
                        var value = _this.val();
                        me.showOrHide(value);
                    });
                }
            });
            cm.init = function () {
                itemTpl = Handlebars.compile($('#tmpl-rights_item').html());
            };
            return cm;
        }(),
        cmp_rights_list : function () {
            var itemTpl,itemSelectTpl,itemRelistTpl;
            var cm = sjApp.extend(formSuperclass,{
                id : 'cmp_rights_list',
                dataIndex : 'rights',
                reset : function(){
                    this.El.find('.releases').html('');
                    this.El.find('.release_select').val('');
                },
                setValue : function(data){
                    if(data && data.rights){
                        var createFlag = data.createFlag||'html';
                        this.El.find('.releases')[createFlag](itemRelistTpl({
                            data : data.rights
                        }));
                    }else{
                        this.reset();
                    }
                },
                getValue : function(){
                    var v = [];
                    this.El.find('.releases li.uploaded_file div.name').each(function(){
                        var _this = $(this);
                        v.push({
                            path: _this.data('path'),
                            type: _this.data('type'),
                            id: _this.data('id'),
                            name: _this.text()
                        });
                    });
                    return v;
                },
                init : function () {
                    this.parentEl.attr('id',this.id).addClass('hidden');
                    this.El = $('<div></div>');
                    this.El.append(itemTpl({
                        id : this.id
                    }));
                    return this.El;
                },createItems:function(){
                    if(rights_p.length||rights_w.length){
                        this.El.find('.existing_releases').html(itemSelectTpl({
                            wq : rights_w,
                            xxq : rights_p
                        }))
                    }
                },initEvent : function () {
                    var me = this;
                    var type = 0;
                    this.El.find('.releases').delegate('span.icon','click',function(){
                       $(this).parents('li.uploaded_file').remove();
                       filterCmp.options.changeData(me);
                    });
                    this.El.find('.release_select').change(function(){
                        var _this = $(this);
                        var optionsEl = _this.find("option:selected");
                        me.setValue({
                            createFlag : 'prepend',
                            rights : [{
                                path : optionsEl.data('path'),
                                type : optionsEl.data('type'),
                                id: _this.val(),
                                name: optionsEl.text()
                            }]
                        });
                        filterCmp.options.changeData(me);
                    });
                    this.El.find('.add_model_release,.add_location_release').click(function(){
                        var _this = $(this);
                        if(_this.hasClass('add_model_release')){
                            type = 0;
                        }else{
                            type = 1;
                        }
                    });
                    this.El.find('#releases_file_picker_c16545').change(function(t) {
                        var _updateProgress = function(t) {
                            var e;
                            e = t.lengthComputable ? t.loaded / t.total * 100 : 50;
                            console.log(Math.round(e))
                            if (100 === Math.round(e)) {

                            }
                        }
                        var e, o;
                        return e = new FormData,
                            e.append("type", type),
                            e.append("loadPhoto", t.target.files[0]), o = $.ajax({
                            url : global_json.uploadPowerUrl,
                            data : e,
                            dataType : 'json',
                            processData : !1,
                            contentType : !1,
                            type : "POST",
                            xhr : function() {
                                var e;
                                return e = $.ajaxSettings.xhr(), e.upload
                                    .addEventListener("progress", _updateProgress), e
                            }
                        }), o.done(function (data) {
                            me.setValue({
                                createFlag : 'prepend',
                                rights : [data]
                            });
                            filterCmp.options.changeData(me);
                        }), o.fail(function (e) {
                            sjApp.errorMsg(e);
                        }), o.complete(function() {
                            // 删css
                        }), o
                    });
                }
            });
            cm.init = function () {
                itemRelistTpl = Handlebars.compile($('#tmpl-rights_item_list_relis').html());
                itemSelectTpl = Handlebars.compile($('#tmpl-rights_item_list_select').html());
                itemTpl = Handlebars.compile($('#tmpl-rights_item_list').html());
            };
            return cm;
        }(),
        cmp_tags : function () {
            var itemTpl;
            var delimiter = [',', ';', ' '];
            var cm = sjApp.extend(formSuperclass,{
                id : 'keywords',
                dataIndex : 'keywords',
                reset : function(){
                    this.getDom().importTags('');
                },
                getValue: function () {
                    var dom = this.getDom();
                    var value = dom.val();
                    return value.split(delimiter).join(';');
                },
                setValue : function(data){
                    var dom = this.getDom();
                    if(data.keywords){
                        dom.importTags(data.keywords.replace(/;/g,delimiter));
                    }
                },
                init : function () {
                    this.El = $(itemTpl({
                        id : this.id
                    }));
                    return this.El;
                },afterRender : function () {
                    var me = this;
                    var dom = this.getDom();
                    dom.tagsInput({
                        width : '100%',
                        'defaultText' : '至少输入5个',
                        'delimiter' : delimiter,
                        maxChars : 30,
                        onAddTag : function() {
                            filterCmp.options.changeData(me);
                        },
                        onRemoveTag : function() {
                            filterCmp.options.changeData(me);
                        }
                    });
                }
            });
            cm.init = function () {
                itemTpl = Handlebars.compile($('#tmpl-tags_item').html());
            };
            return cm;
        }(),
        cmp_size : function () {
            var itemTpl;
            var cm = sjApp.extend(formSuperclass,{
                init : function () {
                    this.El = $('<div></div>');
                    this.El.append(itemTpl());
                    return this.El;
                },createItems : function () {
                },
                setValue : function(data,multipleFlag){
                    if(multipleFlag){
                        this.El.hide();
                    }else{
                        this.El.show();
                        if(data.width && data.height){
                            this.El.find('span').text(data.width+' * '+data.height);
                        }
                    }
                }
            });
            cm.init = function () {
                itemTpl = Handlebars.compile($('#tmpl-size_item').html());
            };
            return cm;
        }()
    };
    !function () {
        var itemTpl;
        photo_details_panel = sjApp.extend(formSuperclass,{
            cmps : {},
            init : function () {
                this.El = $('<ul></ul>');
                return this.El;
            },createItems : function () {
                var _cmp = new cmp();
                for(var key in _cmp){
                    var _liEl = $('<li class="'+key+'"></li>');
                    this.cmps[key] = new _cmp[key]({
                        parentEl : _liEl
                    });
                    _liEl.html(this.cmps[key].El);
                    this.El.append(_liEl);
                }
            },
            reset : function(){
                for(var key in this.cmps){
                    if(this.cmps[key].reset instanceof Function){
                        this.cmps[key].reset();
                    }
                }
            },
            setValue: function (data,multipleFlag) {
                for(var key in this.cmps){
                    if(this.cmps[key].setValue instanceof Function){
                        this.cmps[key].setValue(data,multipleFlag);
                    }
                }
            },
            afterRender: function () {
                for(var key in this.cmps){
                    if(this.cmps[key].afterRender instanceof Function){
                        this.cmps[key].afterRender();
                    }
                }
            }
        });
        photo_details_panel.init = function () {
            //itemTpl = Handlebars.compile($('#tmpl-tags').html());
        };
        photo_details_cmp = new photo_details_panel();
        $('.photo_details_panel').html(photo_details_cmp.El);
        photo_details_cmp.afterRender();
    }();
    var form_cmp = function(options){
        sjApp.apply(this,options);
        if(this.data){
            if(this.data.dateTime){
                this.data.dateTime = this.data.dateTime.replace(/(\d{4}):(\d{2}):(\d{2})/g,function (){
                    return arguments[1]+'-'+arguments[2]+'-'+arguments[3];
                });
            }
            var dd = {
                "id" : this.data.imgUuid,
                //"categoryId" : 1, /* 数字格式 */
                //"type" : 10311,/* 图片类型 作品类型 摄影：10311 绘画插画：10153*/
                //"color" : 12004,/* 图片色彩画面色彩 彩色图片：12004 黑白图片：12009 */
                //"shotEnv" : 4236,/* 拍摄环境  户外：4236 室内：36408 影棚拍摄：4247 都市风光：4244 自然风光：9873 */
                "shotTime" : this.data.dateTime,//'2011-2-2',/* 时间格式 */
                //"shotPlace" : "河南",/* 拍摄地点 */
                //"number" : 4233,/* 画面人数  一个人:4233两个人:4215  三个人:4222  四个人:4221  五个人:4220  六到十个人:4219  大量人群:4224  无人:12109 */
                //"keywords" : "tag1;tag2;tag3",/* 关键字，多个关键字以';'分割 */
                "width" : this.data.imgWidth,/* double类型 */
                "height" : this.data.imgHeight
                //"rightCategory" : 'NR'
            }
            sjApp.applyIf(this.data,dd);
        }
    };
    form_cmp.prototype = {
        validate : function(){
            var data = this.getValue();
            var msg = true;
            var str= '';
            if(!data.type){
                str =  '请选择图片类型！';
            }else if(!data.color){
                str =  '请选择图片色彩！';
            }else if(!data.shotEnv){
                str =  '请选择拍摄环境！';
            }else if(!data.number){
                str =  '请选择画面人数！';
            }
            if(str){
                msg = data.title + '：'+str;
            }
            return msg;
        },
        getValue : function () {
            return this.data||{};
        }
    };

    $('#filer_input').filer({
        limit : 50,
        changeInput : '<div class="add_pic"><span>+</span>添加图片</div>',
        showThumbs : true,
        clipBoardPaste : true,
        templates : {
            box : '<ul class="jFiler-items-list jFiler-items-grid"></ul>',
            item : '<li class="jFiler-item">\
                    <div class="jFiler-item-container">\
                        <div class="jFiler-item-inner">\
                            <div class="jFiler-item-thumb">\
                                <div class="jFiler-item-status"></div>\
                                <div class="jFiler-item-info">\
                                    <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\
                                    <span class="jFiler-item-others">{{fi-size2}}</span>\
                                </div>\
                                {{fi-image}}\
                            </div>\
                            <div class="jFiler-item-assets jFiler-row">\
                                <ul class="list-inline pull-left">\
                                    <li>{{fi-progressBar}}</li>\
                                </ul>\
                                <ul class="list-inline pull-right">\
                                    <li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li>\
                                </ul>\
                            </div>\
                        </div>\
                    </div>\
                </li>',
            itemAppend : '<li class="jFiler-item">\
                        <div class="jFiler-item-container">\
                            <div class="jFiler-item-inner">\
                                <div class="jFiler-item-thumb">\
                                    <div class="jFiler-item-status"></div>\
                                    <div class="jFiler-item-info">\
                                        <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\
                                        <span class="jFiler-item-others">{{fi-size2}}</span>\
                                    </div>\
                                    {{fi-image}}\
                                </div>\
                                <div class="jFiler-item-assets jFiler-row">\
                                    <ul class="list-inline pull-left">\
                                        <li><span class="jFiler-item-others">{{fi-icon}}</span></li>\
                                    </ul>\
                                    <ul class="list-inline pull-right">\
                                        <li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li>\
                                    </ul>\
                                </div>\
                            </div>\
                        </div>\
                    </li>',
            itemAppendToEnd : false,
            removeConfirmation : true,
            _selectors : {
                list : '.jFiler-items-list',
                item : '.jFiler-item',
                remove : '.jFiler-item-trash-action'
            }
        },
        uploadFile : {
            url : global_json.uploadFileUrl,
            data : null,
            dataType : "json",
            type : 'POST',
            enctype : 'multipart/form-data',
            beforeSend : function() {
            },
            success : function(data, el, l, p, o, s, id, textStatus, jqXHR) {
                var fObj = filterCmp.files_list[id];
                fObj.form_cmp = new form_cmp({
                    data : sjApp.apply(data,{
                        title : fObj.file.name?fObj.file.name.split('.')[0]:""
                    })
                });
                var parent = el.find(".jFiler-jProgressBar").parent();
                el.find(".jFiler-jProgressBar").fadeOut("slow", function() {
                    $("<div class=\"jFiler-item-others text-success\"><i class=\"icon-jfi-check-circle\"></i> 成功</div>")
                        .hide().appendTo(parent).fadeIn("slow");
                });
            },
            error : function(el) {
                var parent = el.find(".jFiler-jProgressBar").parent();
                el.find(".jFiler-jProgressBar").fadeOut("slow", function() {
                    $("<div class=\"jFiler-item-others text-error\"><i class=\"icon-jfi-minus-circle\"></i> 失败</div>")
                        .hide().appendTo(parent).fadeIn("slow");
                });
            },
            statusCode : null,
            onProgress : null,
            onComplete : null
        },
        onRemove : function(itemEl, file) {
            // var file = file.name;
            // $.post('./php/remove_file.php', {file: file});
            var selecteesEl = itemEl
                .find('div.jFiler-item-container.ui-selected');
            if (selecteesEl.length) {
                selecteesEl.removeClass('ui-selected');
                this.imgUnSelected();
            }
        },
        onEmpty : function() {
            this.selectable = false;
        },
        onSelect : function() {
            if (!this.selectable || this.selectable === false) {
                var jFilerEl = arguments[2];
                this.selectable = jFilerEl.find('.jFiler-items-grid')
                    .selectable({
                        selected : this.imgOnSelected,
                        unselected : this.imgUnSelected,
                        cancel : 'a',
                        filter : "li.jFiler-item div.jFiler-item-container"
                    });
                // this.selectable = true;
            }
        },
        changeData : function(me){
            var list = filterCmp.files_list;
            $('div.jFiler-item-container.ui-selected').each(function () {
                var _thisParent = $(this).parent();
                var fObj = list[_thisParent.data('jfilerIndex')];
                if (fObj && fObj.form_cmp) {
                    var v = me.getValue();
                    fObj.form_cmp.data[me.dataIndex] = v;
                    if(me.dataIndex == 'title'){
                        var s = v.substring(0, 22);
                        var str = (s.length < v.length ? s.substring(0, s.length - 3) + "..." : v);
                        fObj.html.find('.jFiler-item-title').text(str);
                    }
                }
            });
        },
        validates : function(){
            var list = filterCmp.files_list;
            for(var i= 0,obj;obj=list[i];i++){
                var rs = obj.form_cmp.validate();
                if(rs !== true){
                    return rs
                }
            }
            return true;
        },
        afterRender : function() {
            filterCmp = $('#filer_input').prop("jFiler");
            var me = this;
            sjApp.applyIf(this, {
                rightBodyEnabled : function(el) {
                    var rbEl = $('.right_body');
                    var firstFlag = rbEl.hasClass('disabled');

                    var list = filterCmp.files_list;
                    var fObj = list[el.data('jfilerIndex')];
                    if (fObj) {
                        if (firstFlag) {
                            photo_details_cmp.reset();
                            // 第一次赋组件值的时候
                            photo_details_cmp.setValue(fObj.form_cmp.getValue());
                        } else {
                            var multiple = true;
                            photo_details_cmp.setValue(fObj.form_cmp.getValue(),multiple);
                        }
                    }
                    $('.right_body').removeClass('disabled');
                    $('.right_body input').removeAttr('disabled');
                },
                rightBodyDisabled : function() {
                    $('.right_body').addClass('disabled');
                    $('.right_body input').attr('disabled', 'disabled');
                },
                imgOnSelected : function(evt, elObj) {
                    me.rightBodyEnabled($(elObj.selected).parent());
                },
                imgUnSelected : function() {
                    var selecteesEl = $('.left_body li.jFiler-item div.jFiler-item-container.ui-selected');
                    if (!selecteesEl.length) {
                        me.rightBodyDisabled();
                    }
                }
            });
            $('#all_select').click(function() {
                var selecteesEl = $('li.jFiler-item div.jFiler-item-container');// me.selectable.selectable('instance').selectees;
                selecteesEl.each(function() {
                    var _this = $(this);
                    _this.addClass('ui-selected');
                    me.imgOnSelected.call(me.selectable, null, _this);
                });
            });
            $('#select_del').click(function() {
                var selecteesEl = $('li.jFiler-item div.jFiler-item-container.ui-selected');
                if (!selecteesEl.length) {
                    alert('请选择图片。');
                    return;
                }
                var cf = me.templates.removeConfirmation
                    ? confirm(me.captions.removeConfirmation)
                    : true;
                if (cf) {
                    selecteesEl.each(function() {
                        var _this = $(this);
                        _this.find('.jFiler-item-trash-action').click();
                    });
                }
            });
            $('#select_del_all').click(function() {
                var selecteesEl = $('li.jFiler-item div.jFiler-item-container');
                if (!selecteesEl.length) {
                    alert('没有可删除的图片。');
                    return;
                }
                var cf = me.templates.removeConfirmation
                    ? confirm(me.captions.removeConfirmation)
                    : true;
                if (cf) {
                    /**selecteesEl.each(function() {
								var _this = $(this);
								_this.find('.jFiler-item-trash-action').click();
							});*/
                    filterCmp.reset();
                }
            });

            $('.right_body .button.save,.right_body .button.submit').click(function () {
                var rs;
                if((rs=me.validates()) !==true){
                    return sjApp.showMsg({
                        cls : 'error',
                        html : rs || '信息填写不完整，请检查后再提交！'
                    });
                }
                var list = filterCmp.files_list;
                var _this = $(this);
                var _thisParent = _this.parent();
                if (list.length) {
                    var commitState = _this.hasClass('save')?0:1;
                    var filesData = {
                        name : '草稿',
                        commitState : commitState,
                        data : []
                    };
                    list.forEach(function(obj) {
                        if (obj.uploaded) {
                            var d = obj.form_cmp.getValue();
                            filesData.data.push(d);
                            if (!filesData.url) {
                                filesData.url = d.url;
                            }
                        }
                    });
                    if (filesData.data.length) {
                        _thisParent.addClass('disabled');
                        $.ajax({
                            // 提交数据的类型 POST GET
                            type : "POST",
                            // 提交的网址
                            url : global_json.save,
                            data : {
                                jsonData : sjApp.stringify(filesData)
                            },
                            dataType : "json",
                            success : function(data) {
                                _thisParent.removeClass('disabled');
                                if(data  && data instanceof Object && !data.error){
                                    sjApp.showMsg({
                                        cls : 'success',
                                        html : commitState?'提交GIC成功！':'保存草稿成功，可在个人中心->授权->草稿箱中查看！'
                                    });
                                }
                            },
                            error : function(e) {
                                _thisParent.removeClass('disabled');
                                sjApp.errorMsg(e);
                            }
                        });
                    }
                }
            });
        }
    });
})